<?php

/*
 * 这不是一个开放软件，您不能用于商业应用
 * 不允许对程序代码以任何形式任何目的的再发布。
 * Copyright (c) 2015 YOUM.Co.Ltd. All rights reserved..
 * 网站地址：http://www.huishuojs.com
 * Author Zhyu
 */

/**
 * @author Zhyu
 * @date 2016-01-27 10:46:02
 * @copyright 杭州晖硕有码科技
 */
class Login extends CI_Controller{
    //put your code here
    public function __construct() {
        parent::__construct();
    }
    //登录页面
    public function index(){
        $this->data['site_title']='登录';
        $this->load->view('/wap/login',$this->data);
        
    }
    //处理登录数据
    public function login(){
        $where['username']=$_POST['username'];
        $this->load->model('user_model');
        $user=$this->user_model->checkUser($where);
        $result=array();
        if($user && $user['password']==md5($_POST['password'])){
            $result['success']='1';
            $result['msg']='登录成功';
            $result['url']='/';
            $this->load->library('wx_visitor');
            $user['admin_type']='user';
            $user['admin']=$user;
            $this->wx_visitor->assign($user);
        }else{
            $result['success']='0';
            $result['msg']='密码错误';
        }
        echo json_encode($result);
    }
    public function check_username(){
        $where['username']=$_POST['username'];
        $this->load->model('user_model');
        $user=$this->user_model->checkUser($where);
        $success=false;
        if($user){
            $success=true;
        }
        echo json_encode($success);
    }
}
